let app = getApp()
let cs = app.data.common_store
// 翻译电码
let conv = (conv_type, code) => {
	if (code != "" && typeof (code) != "undefined") {
		// 电码转文字
		if (conv_type == "c2w") {
			let conv_code = ""
			let code_arr = code.split(" ")
			for (let i = 0; i < code_arr.length; i++) {
				if (code_arr[i] != "") {
					
					let n = cs.mc.indexOf(code_arr[i])
					if (n != -1) {
						conv_code += cs.mw[n]
					}
					else if (n == -1) {
						conv_code += "*"
					}
				}
				else if (code_arr[i] == "") {
					conv_code += " "
				}
			}
			code = conv_code
		}
		// 文字转电码
		else if(conv_type == "w2c") {
			let conv_code = ""
			for(let i =0; i < code.length; i ++) {
				if(code[i] != " ") {
					let n = cs.mw.indexOf(code[i])
					if(n != -1) {
						conv_code += cs.mc[n]
					}
					else {
						conv_code += "*"
					}
					
				}
				conv_code += " "
			}
			code = conv_code
		}
	}
	return code

}

module.exports = {
	conv: conv,
}